﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using Model;

namespace DAL
{
    public class D_ExperienceCom : IExperienceCom
    {
        WishDayEntities _e;
        public D_ExperienceCom()
        {
            _e = new WishDayEntities();
        }
        public void Add(EperienceCom obj)
        {
            _e.EperienceCom.Add(obj);
            _e.SaveChanges();
        }

        public void Delete(int id)
        {
            var data = _e.EperienceCom.Find(id);
            _e.ExperienceDetail.Remove(_e.ExperienceDetail.Find(data.EDID));
            _e.EperienceCom.Remove(data);
            _e.SaveChanges();
        }

        public EperienceCom FindById(int id)
        {
            return _e.EperienceCom.Find(id);
        }

        public List<EperienceCom> GetAll()
        {
            return _e.EperienceCom.ToList();
        }

        public void Update(int id, EperienceCom obj)
        {
            var data = _e.EperienceCom.Find(id);
            data.EDID = obj.EDID;
            data.TemplateID = obj.TemplateID;
            _e.SaveChanges();
        }
    }
}
